package online.test1;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @Author 28021
 * @Date 2022/10/11
 */
public class ArrayListBoardInput {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        System.out.println("请输入学生的个数：");
        int stuSum = in.nextInt();
        ArrayList<Student> students = new ArrayList<>();
        for (int i = 0; i < stuSum; i++) {
            Student s = new Student();

            System.out.println("请输入学生的姓名：");
            String name = in.next();
            s.setName(name);

            System.out.println("请输入学生"+name+"的年龄：");
            int age = in.nextInt();
            s.setAge(age);

            students.add(s);
        }
//        System.out.println(students.size());
        System.out.println(students);
        //遍历
        for (int i = 0; i < students.size(); i++) {
            System.out.println(students.get(i).getName()+","+students.get(i).getAge());
        }
    }

}
class Student{
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    public String toString() {
        return "Student{name = " + name + ", age = " + age + "}";
    }
}

